package com.eunion.core.common.excel;

/**
 * 对excel某列中数据的限制
 * 
 * @author hallwong
 *
 */
public class ExcelColumnRestriction {

    public enum Type {
        Number, String;
    }

    private final String field;

    private final String name;

    private final int index;

    private final Type type;

    private final int length;

    private boolean allowNull = false;

    private Object defaultValue;
    
    private boolean datetimeType = false;
    
    private String dateFormat;

    public ExcelColumnRestriction(String name, int index, Type type) {
        this(name, name, index, type, 0);
    }

    public ExcelColumnRestriction(String field, String name, int index, Type type) {
        this(field, name, index, type, 0);
    }

    public ExcelColumnRestriction(String field, String name, int index, Type type, int length) {
        super();
        this.field = field;
        this.name = name;
        this.index = index;
        this.type = type;
        this.length = length;
    }

    /**
     * 为了匹配时间字符串，新加构造函数，by zenggaoping
     * @param field
     * @param name
     * @param index
     * @param type
     * @param length
     * @param dateFormat
     */
    public ExcelColumnRestriction(String field, String name, int index, Type type, int length, String dateFormat) {
        super();
        this.field = field;
        this.name = name;
        this.index = index;
        this.type = type;
        this.length = length;
        this.dateFormat = dateFormat;
        this.datetimeType = true;
    }
    
    public ExcelColumnRestriction defaultValue(Object defaultValue) {
        this.defaultValue = defaultValue;
        this.allowNull = true;
        return this;
    }

    public ExcelColumnRestriction notNull() {
        this.allowNull = false;
        return this;
    }

    public String getName() {
        return name;
    }

    public String getField() {
        return field;
    }

    public int getIndex() {
        return index;
    }

    public Type getType() {
        return type;
    }

    public int getLength() {
        return length;
    }

    public boolean isAllowNull() {
        return allowNull;
    }

    public Object getDefaultValue() {
        return defaultValue;
    }

    public boolean isDatetimeType() {
        return datetimeType;
    }

    public String getDateFormat() {
        return dateFormat;
    }
    
    public ExcelColumnRestriction datetimeType(String dateFormat) {
        this.dateFormat = dateFormat;
        this.datetimeType = true;
        return this;
    }

}
